package us.mooresr.geartrack.server.handler;

import java.util.ArrayList;

import us.mooresr.geartrack.server.DAO;
import us.mooresr.geartrack.shared.action.GetAllLocationsAction;
import us.mooresr.geartrack.shared.action.GetAllLocationsResult;
import us.mooresr.geartrack.shared.model.Location;

import com.googlecode.objectify.Query;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;

public class GetAllLocationsActionHandler implements ActionHandler<GetAllLocationsAction, GetAllLocationsResult> {

	@Override
	public GetAllLocationsResult execute(GetAllLocationsAction arg0,
			ExecutionContext arg1) throws ActionException {
		DAO dao = new DAO();
		

		
		ArrayList<Location> locationList = new ArrayList<Location>();
		
		Query<Location> q = dao.ofy().query(Location.class);
		
		for (Location r : q) {
			locationList.add(r);
		}
		
		return new GetAllLocationsResult(locationList);
	}

	@Override
	public Class<GetAllLocationsAction> getActionType() {
		return GetAllLocationsAction.class;
	}

	@Override
	public void undo(GetAllLocationsAction arg0, GetAllLocationsResult arg1,
			ExecutionContext arg2) throws ActionException {
		// TODO Auto-generated method stub
		
	}

}
